# To change this template, choose Tools | Templates
# and open the template in the editor.

require 'rubygems'
require 'json/pure'

module GoogleSearch
  class Result
    def initialize(json_search_result)
      @json_search_result = json_search_result
    end

    def self.parse(result)
      Result.new JSON.parse(result)
    end

    def unescaped_url
      @json_search_result['unescapedUrl']
    end

    def url
      @json_search_result['url']
    end

    def visible_url
      @json_search_result['visibleUrl']
    end

    def cache_url
      @json_search_result['cacheUrl']
    end

    def title
      @json_search_result['title']
    end

    def title_without_formatting
      @json_search_result['titleNoFormatting']
    end

    def content
      @json_search_result['content']
    end

    def == (other)
      url == other.url && title == other.title
    end

    def to_s
      "#{title}\n#{content}\n#{url}"
    end
  end
end
